package com.crm.service.permission;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.crm.dao.permission.MenubarDAO;
import com.crm.exception.ServiceException;
import com.crm.pojo.Menubar;

@Service
@Transactional(rollbackFor = Exception.class)
public class MenubarService {

	@Autowired
	private MenubarDAO menubarDAO;

	/**
	 * 查询所有功能
	 * 
	 * @return
	 */
	public List<Menubar> queryAllMenubar(int curpage, int pagesize) {
		PageRequest page = new PageRequest(curpage - 1, pagesize);
		return menubarDAO.queryAll(page);
	}

	public Long queryCount() {
		return menubarDAO.count();
	}

	public Menubar queryOneName(String text){
		return menubarDAO.queryOne(text);
	}
	
	/**
	 * 添加功能
	 * 
	 * @param mname
	 * @throws ServiceException
	 */
	public void addMenubar(String text) throws ServiceException {
		try {
			Menubar menubar = new Menubar();
			menubar.setMname(text);
			menubarDAO.save(menubar);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
}
